#******************************************************************************
# * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# *
# * NVIDIA CORPORATION and its licensors retain all intellectual property
# * and proprietary rights in and to this software, related documentation
# * and any modifications thereto.  Any use, reproduction, disclosure or
# * distribution of this software and related documentation without an express
# * license agreement from NVIDIA CORPORATION is strictly prohibited.
# ******************************************************************************

CUSPARSELT_PATH   ?= /usr
CUDA_TOOLKIT_PATH ?= /usr/local/cuda
NVCC              := ${CUDA_TOOLKIT_PATH}/bin/nvcc
CXXFLAGS          := -std=c++14 -Xcompiler -fopenmp ${CXXFLAGS}
CPPFLAGS          := -I${CUDA_TOOLKIT_PATH}/include -I${CUSPARSELT_PATH}/include ${CPPFLAGS}
LDFLAGS           := -L${CUSPARSELT_PATH}/lib64 ${LDFLAGS}
LDLIBS            := -lcusparseLt -lcusparse -ldl ${LDLIBS}
TARGETS           := sparse_fp32 sparse_fp16 sparse_int8 sparse_fp8 sparse_fp4

all: ${TARGETS}

sparse_fp32: sparse.cpp
	${NVCC} -DAB_TYPE=FP32 ${CXXFLAGS} ${CPPFLAGS} -o $@ $^ ${LDFLAGS} ${LDLIBS}

sparse_fp16: sparse.cpp
	${NVCC} -DAB_TYPE=FP16 ${CXXFLAGS} ${CPPFLAGS} -o $@ $^ ${LDFLAGS} ${LDLIBS}

sparse_int8: sparse.cpp
	${NVCC} -DAB_TYPE=INT8 ${CXXFLAGS} ${CPPFLAGS} -o $@ $^ ${LDFLAGS} ${LDLIBS}

sparse_fp8:  sparse.cpp
	${NVCC} -DAB_TYPE=FP8  ${CXXFLAGS} ${CPPFLAGS} -o $@ $^ ${LDFLAGS} ${LDLIBS}

sparse_fp4:  sparse.cpp
	${NVCC} -DAB_TYPE=FP4  ${CXXFLAGS} ${CPPFLAGS} -o $@ $^ ${LDFLAGS} ${LDLIBS}

test: ${TARGETS}
	./sparse_fp32 3 9
	./sparse_fp16 4 9
	./sparse_int8 5 9

clean:
	rm -f ${TARGETS}

.PHONY: clean all test
